<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="queryList" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="flex flex-1" :model="store.searchState" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="bqid">
          <SelectArea v-model:value="store.searchState.bqid" use-cache set-cache @select="queryList" />
        </a-form-item>
        <a-form-item name="bedCode" class="ml-2">
          <a-input v-model:value="store.searchState.bedCode" class="w-52" placeholder="床位号" allow-clear />
        </a-form-item>
        <a-form-item name="zjm" class="ml-2">
          <a-input
            v-model:value="store.searchState.zjm"
            class="w-52"
            placeholder="姓名/助记码/住院号"
            allow-clear
            @change="queryList"
            @keydown.enter="queryList"
          />
        </a-form-item>
        <a-form-item v-if="store.tabActiveKey !== 4" name="inpAdvice" class="ml-4">
          <a-radio-group v-model:value="store.searchState.inpAdvice" @change="queryList">
            <a-radio value="">全部</a-radio>
            <a-radio value="1">长期</a-radio>
            <a-radio value="0">临时</a-radio>
          </a-radio-group>
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="float-left mb-2">
        <a-radio-group v-model:value="store.tabActiveKey" button-style="solid" :disabled="store.loading" @change="queryList">
          <a-radio-button :value="0">未签收 ({{ store.unSignTodayCountData.wqsCount || 0 }})</a-radio-button>
          <a-radio-button :value="1">今日申请 ({{ store.unSignTodayCountData.dsqCount || 0 }})</a-radio-button>
          <a-radio-button :value="5">今日签停 ({{ store.unSignTodayCountData.qtCount || 0 }})</a-radio-button>
          <a-radio-button :value="2">全部医嘱 ({{ store.allOrderCountData.allCount || 0 }})</a-radio-button>
          <a-radio-button :value="4">医嘱核对单 </a-radio-button>
          <a-radio-button :value="3">医嘱执行单 </a-radio-button>
        </a-radio-group>
        <a-radio-group v-if="store.tabActiveKey === 4" v-model:value="store.checkAdvType" class="ml-8" @change="getCheckRightData">
          <a-radio value="">全部</a-radio>
          <a-radio value="1">长期</a-radio>
          <a-radio value="0">临时</a-radio>
          <a-radio value="2">出院带药</a-radio>
        </a-radio-group>
      </div>
      <UnSign v-if="store.tabActiveKey === 0" />
      <TodaySign v-if="store.tabActiveKey === 1" />
      <AllOrder v-if="store.tabActiveKey === 2" />
      <CheckList v-if="store.tabActiveKey === 4" ref="executionCheckList" />
      <ExecutionOrder v-if="store.tabActiveKey === 3" ref="executionOrderRef" />
      <TodayStop v-if="store.tabActiveKey === 5" ref="signStopRef" />
    </a-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import SearchContainer from '@/components/SearchContainer'
import SelectArea from '@/components/SelectArea'
import UnSign from './components/UnSign'
import TodaySign from './components/TodaySign'
import AllOrder from './components/AllOrder'
import ExecutionOrder from './components/ExecutionOrder'
import CheckList from './components/CheckList.vue'
import TodayStop from './components/TodayStop.vue'
import useStore from './store'

const store = useStore()
const formRef = ref(null)
const executionOrderRef = ref(null)
const executionCheckList = ref(null)
const signStopRef = ref(null)
const queryList = () => {
  if (store.tabActiveKey === 2) {
    store.fetchAllOrderData()
  } else if (store.tabActiveKey === 3) {
    setTimeout(() => {
      executionOrderRef.value.getData()
    }, 100)
  } else if (store.tabActiveKey === 4) {
    setTimeout(() => {
      executionCheckList.value.getData()
    }, 100)
  } else if (store.tabActiveKey === 5) {
    setTimeout(() => {
      signStopRef.value.getData()
    }, 100)
  } else {
    store.fetchSignData()
  }
  store.fetchSignCountData()
  store.fetchAllOrderCountData()
}
const getCheckRightData = () => {
  executionCheckList.value.getAdvData()
}
onMounted(() => {
  store.tabActiveKey = 0
  store.searchState.zjm = ''
  store.searchState.inpAdvice = ''
  if (store.tabActiveKey === 2) {
    store.fetchAllOrderData()
  } else if (store.tabActiveKey === 3) {
    setTimeout(() => {
      executionOrderRef.value.getData()
    }, 100)
  } else {
    store.fetchSignData()
  }
  store.fetchSignCountData()
  store.fetchAllOrderCountData()
})
</script>

<style lang="less" scoped>
:deep(.ant-table-row-expand-icon) {
  display: none;
}
</style>
